#include "tevampinfotab.h"
#include "tevampfeature.h"
#include <QHeaderView>
#include <QHBoxLayout>
#include <QString>

TEVAmpInfoTab::TEVAmpInfoTab(QWidget *parent)
    : MapInfoTab(parent)
    , m_tevAmpFeature(std::make_shared<TEVAmpFeature>())
    , m_pChartBox(new QGroupBox("图谱数据"))
    , m_pChartData(new QTextEdit)
    , m_pMainLayout(new QHBoxLayout(this))
    , m_pLayout(new QHBoxLayout(this))
{
    // 创建布局
    m_pLayout->addWidget(m_pChartData);
    m_pChartBox->setLayout(m_pLayout);

    m_pMainLayout->addWidget(m_tevAmpFeature->initUI(this));
    m_pMainLayout->addWidget(m_pChartBox);

    setLayout(m_pMainLayout);

    // 添加TEV幅值特性组件
    addFeature(std::dynamic_pointer_cast<IMapInfoFeature>(m_tevAmpFeature));
}

TEVAmpInfoTab::~TEVAmpInfoTab()
{
    delete m_pChartBox;
    delete m_pChartData;
    delete m_pMainLayout;
    delete m_pLayout;
}

void TEVAmpInfoTab::setDataTypeCode(uint8_t code)
{
    // 数据会通过特性组件显示
    if (m_tevAmpFeature) {
        m_tevAmpFeature->setDataTypeCode(code);
    }
}

void TEVAmpInfoTab::setDataLength(int32_t length)
{
    // 数据会通过特性组件显示
    if (m_tevAmpFeature) {
        m_tevAmpFeature->setDataLength(length);
    }
}

void TEVAmpInfoTab::setCreateTime(const QString& time)
{
    // 数据会通过特性组件显示
    if (m_tevAmpFeature) {
        m_tevAmpFeature->setCreateTime(time);
    }
}

void TEVAmpInfoTab::setChartProperty(const DataSpecificationGW::SpectrumCharacter& property)
{
    // 数据会通过特性组件显示
    if (m_tevAmpFeature) {
        m_tevAmpFeature->setChartProperty(property);
    }
}

void TEVAmpInfoTab::setDeviceName(const QString& name)
{
    // 数据会通过特性组件显示
    if (m_tevAmpFeature) {
        m_tevAmpFeature->setDeviceName(name);
    }
}

void TEVAmpInfoTab::setDeviceCode(const QString& code)
{
    // 数据会通过特性组件显示
    if (m_tevAmpFeature) {
        m_tevAmpFeature->setDeviceCode(code);
    }
}

void TEVAmpInfoTab::setMeasurementName(const QString& name)
{
    // 数据会通过特性组件显示
    if (m_tevAmpFeature) {
        m_tevAmpFeature->setMeasurementName(name);
    }
}

void TEVAmpInfoTab::setMeasurementCode(const QString& code)
{
    // 数据会通过特性组件显示
    if (m_tevAmpFeature) {
        m_tevAmpFeature->setMeasurementCode(code);
    }
}

void TEVAmpInfoTab::setChannelFlag(int64_t flag)
{
    // 数据会通过特性组件显示
    if (m_tevAmpFeature) {
        m_tevAmpFeature->setChannelFlag(flag);
    }
}

void TEVAmpInfoTab::setDataType(uint8_t type)
{
    // 数据会通过特性组件显示
    if (m_tevAmpFeature) {
        m_tevAmpFeature->setDataType(type);
    }
}

void TEVAmpInfoTab::setAmplitudeUnit(uint8_t unit)
{
    if (m_tevAmpFeature) {
        m_tevAmpFeature->setAmplitudeUnit(unit);
    }
}

void TEVAmpInfoTab::setAmplitudeLowerLimit(float lowerLimit)
{
    if (m_tevAmpFeature) {
        m_tevAmpFeature->setAmplitudeLowerLimit(lowerLimit);
    }
}

void TEVAmpInfoTab::setAmplitudeUpperLimit(float upperLimit)
{
    if (m_tevAmpFeature) {
        m_tevAmpFeature->setAmplitudeUpperLimit(upperLimit);
    }
}

void TEVAmpInfoTab::setTransientVoltageAmplitudeData(const QString& data)
{
    if (m_tevAmpFeature) {
        m_tevAmpFeature->setTransientVoltageAmplitudeData(data);
    }
    // 在图表数据框显示数据
    m_pChartData->setText(data);
}

void TEVAmpInfoTab::setMaxTransientVoltageAmplitude(float amplitude)
{
    if (m_tevAmpFeature) {
        m_tevAmpFeature->setMaxTransientVoltageAmplitude(amplitude);
    }
}

void TEVAmpInfoTab::setPulseCount(int32_t count)
{
    if (m_tevAmpFeature) {
        m_tevAmpFeature->setPulseCount(count);
    }
}

void TEVAmpInfoTab::setBackgroundFileName(const QString& fileName)
{
    if (m_tevAmpFeature) {
        m_tevAmpFeature->setBackgroundFileName(fileName);
    }
}

void TEVAmpInfoTab::setReservedData(const QByteArray& byte)
{
    // 数据会通过特性组件显示
    if (m_tevAmpFeature) {
        m_tevAmpFeature->setReservedData(byte);
    }
}
